home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 52498 / 52498.xpi / chrome / optimizegoogle.jar / content / optimizegoogle / javascript.js < prev    next >
Text File  |  2009-11-04  |  42KB  |  1,056 lines

  1. var get_search_form = function() {
  2.     var val = document.evaluate("//form[@action='/search']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
  3.               document.evaluate("//form[@action='http://www.google.com/search']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
  4.               document.evaluate("//form[@action='/custom']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
  5.               document.evaluate("//form[@action='/unclesam']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
  6.               document.evaluate("//form[@action='/linux']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
  7.               document.evaluate("//form[@action='/bsd']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
  8.               document.evaluate("//form[@action='/mac']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ||
  9.               document.evaluate("//form[@action='/microsoft']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  10.     return val;
  11. };
  12.  
  13. var get_random_id = function(size) {
  14.     var chars = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
  15.     var id = '';
  16.     for (var i=0;i<size;++i) {
  17.         id += chars[Math.round(Math.random()*(chars.length-1))];
  18.     }
  19.     return id;
  20. };
  21. var selectAllNodes = function(doc, context, xpath) {
  22.    var nodes = doc.evaluate(xpath, context, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  23.    var result = new Array( nodes.snapshotLength );
  24.    for (var x=0; x<result.length; x++) {
  25.       result[x] = nodes.snapshotItem(x);
  26.    }
  27.    return result;
  28. };
  29.  
  30. var createLinks = function() {
  31.     //var googFonts = selectAllNodes(document, document.body, "//FONT[contains(@color,'#008000')]");
  32.     //Changed on 16-08-2009. Thanks go to Chris000001 & bugblatter
  33.     var googFonts = selectAllNodes(document, document.body, "//div[@id='ImgContent']/table/tbody/tr/td[starts-with(@id, 'tDataText')]/div/div/cite");
  34.     var googLinks = selectAllNodes(document, document.body, "//A[contains(@href,'/imgres?imgurl=')][contains(@href,'&imgrefurl=')]");
  35.     
  36.     for (var x=0; x<googLinks.length; x++) {
  37.         var target = googLinks[x].getAttribute("target");
  38.         if (!target) {
  39.             target = "";
  40.         }
  41.         
  42.         
  43.         var gmatch   = googLinks[x].href.match( /\/imgres\?imgurl\=(.*?)\&imgrefurl\=/ );
  44.         //var urlmatch = googLinks[x].href.match(/\&imgrefurl\=(.*?)\&([a-z]+)=/);
  45.         //Changed on 16-08-2009. Thanks go to bugblatter
  46.         var urlmatch = googLinks[x].href.match(/\&imgrefurl\=(.*?)\&usg=/);
  47.         if (googFonts[x].innerHTML.length==0) {
  48.             googFonts[x].innerHTML = "...";
  49.         }
  50.         
  51.         if (gmatch) {
  52.             googFonts[x].innerHTML="<a href=\""+unescape(urlmatch[1])+"\" target=\""+target+"\">"+googFonts[x].innerHTML+"</a>";
  53.             googLinks[x].setAttribute("class", "ext");
  54.             
  55.             // make compatible with piclens
  56.             // googLinks[x].href = unescape(gmatch[1]);
  57.             //googLinks[x].setAttribute('onclick', "document.location.href='" + unescape(gmatch[1]) + "';return false;")
  58.             googLinks[x].setAttribute('onmouseup', "this.href='" + unescape(gmatch[1]) + "';return true;")
  59.         }
  60.     }
  61. };
  62.  
  63. // start auto scroll
  64. var startNr;
  65. var itemsQuantity;
  66. var storageContainer;
  67. var query;
  68. var requested;
  69.  
  70. var Remain = {
  71.     valueOf : function() {
  72.         var sc = window.scrollY; //document.body.scrollTop;
  73.         var wh = window.innerHeight ? window.innerHeight : document.body.clientHeight;
  74.         var total = (document.body.scrollHeight - wh);
  75.         return total - sc;
  76.     }
  77. };
  78.  
  79. var watch_scroll = function() {
  80.     var self = arguments.callee;
  81.     if (Remain < 500) {
  82.         do_request();
  83.     }
  84.     setTimeout(self,100);
  85. };
  86.  
  87. var do_request = function() {
  88.     if (requested == startNr) return;
  89.     requested = startNr;
  90.     
  91.     var iframe = document.createElement("iframe");
  92.     iframe.width = document.width;
  93.     iframe.height = 1;
  94.     iframe.style.margin = "0 0 0 -10000px";
  95.     iframe.style.position = "absolute";
  96.     iframe.style.top = 0;
  97.     iframe.style.left = 0;
  98.     document.body.appendChild(iframe);
  99.     iframe.addEventListener("load", function() {
  100.         var isNextExist = iframe.contentDocument.evaluate("//div[@id='nn']", iframe.contentDocument.body, null, 9, null).singleNodeValue
  101.             || iframe.contentDocument.evaluate("//span[@id='nn']", iframe.contentDocument.body, null, 9, null).singleNodeValue
  102.             || document.evaluate("//span[@class='csb ch']/parent::a", document, null, 9, null).singleNodeValue;;
  103.         //var list = iframe.contentDocument.evaluate("//li[contains(@class,'g')]", iframe.contentDocument.body, null, 6, null);
  104.         // Changed on 16-08-2009
  105.         var list = iframe.contentDocument.evaluate("//li[@class='g' or @class='g w0']", iframe.contentDocument.body, null, 6, null);
  106.         if (list.snapshotLength==0) {
  107.             // if images
  108.             list = iframe.contentDocument.evaluate("//div[@id='ImgContent']/table/tbody/tr", iframe.contentDocument.body, null, 6, null);
  109.         }
  110.         for (var i = 0; i < list.snapshotLength; i++) {
  111.             var oldNode = list.snapshotItem(i);
  112.             var newNode = document.importNode(oldNode,true);
  113.             storageContainer.appendChild(newNode);
  114.         }
  115.         if (!!isNextExist) {
  116.             startNr += itemsQuantity;
  117.         } else {
  118.             // add option to remove filter
  119.             var removefilter = iframe.contentDocument.evaluate("//a[contains(@href,'filter=0')]/parent::i/parent::p", iframe.contentDocument.body, null, 9, null).singleNodeValue;
  120.             if (removefilter) {
  121.                 storageContainer.appendChild(removefilter);
  122.             }
  123.             var n = storageContainer;
  124.             do {
  125.                 while (n.nextSibling) {
  126.                     n = n.nextSibling;
  127.                     if (n.tagName != 'SCRIPT' && n.id != 'navbar' && n.id != 'nav' && n.style) n.style.display = 'block';
  128.                 }
  129.                 n = n.parentNode;
  130.             } while (n);
  131.         }
  132.         iframe.src = "";
  133.         document.body.removeChild(iframe);
  134.     }, false);
  135.     iframe.src = "http://"+location.host+location.pathname+query.replace(/start=\d*/,"start=" + startNr) + "#disable-userscript";
  136. };
  137. // end autoscroll
  138.  
  139. var OptimizeGoogle = {
  140.     
  141.     t: function(name) {
  142.         try {
  143.             return textarr[name];
  144.         } catch (e) {
  145.             return name;
  146.         }
  147.     },
  148.     
  149.     truncateURL: function(url, maxChars) {
  150.         if (url.length <= maxChars) return url;
  151.         var newurl = "";
  152.         for (var i = 0; i <= url.length; i+= maxChars + 1) {
  153.             newurl += url.substring(i, i+maxChars);
  154.             if (i+maxChars <= url.length)
  155.                 newurl += "<wbr>";
  156.         }
  157.         return newurl;
  158.     },
  159.     
  160.     addAutoPager: function() {
  161.         window.onresize = function() { return true; }
  162.         var next = document.evaluate("//div[@id='nn']/parent::a", document, null, 9, null).singleNodeValue
  163.                 || document.evaluate("//span[@id='nn']/parent::a", document, null, 9, null).singleNodeValue
  164.                 || document.evaluate("//span[@class='csb ch']/parent::a", document, null, 9, null).singleNodeValue;
  165.         // web search || image search
  166.         //storageContainer =   document.evaluate("//li[contains(@class,'g')]/parent::ol", document, null, 9, null).singleNodeValue
  167.         //                    || document.evaluate("//div[@id='ImgContent']/table/tbody", document, null, 9, null).singleNodeValue;
  168.         //Changed on 16-08-2009
  169.         storageContainer = document.evaluate("//li[@class='g' or @class='g w0']/parent::ol", document, null, 9, null).singleNodeValue
  170.                         || document.evaluate("//div[@id='ImgContent']/table/tbody", document, null, 9, null).singleNodeValue;
  171.         
  172.         // if next page and result
  173.         if ( next && storageContainer ) {
  174.             query = next.href.substr(next.href.indexOf("?"));
  175.             startNr = (query.match(/start=(\d*)/))[1] - 0;
  176.             var tmp = query.match(/num=(\d*)/);
  177.             itemsQuantity = tmp ? (tmp[1] - 0) : 10;
  178.             window.addEventListener("load", watch_scroll, false);
  179.             var n = storageContainer;
  180.             do {
  181.                 while (n.nextSibling) {
  182.                     n = n.nextSibling;
  183.                     if (n.style) n.style.display = 'none';
  184.                 }
  185.                 n = n.parentNode;
  186.             } while (n);
  187.             var navbar = document.getElementById('navbar') || document.getElementById('nav');
  188.             if (navbar) navbar.style.display = 'none';
  189.         }
  190.     },
  191.     
  192.     addGlobalStyle: function(css) {
  193.         var style = document.createElement("style");
  194.         style.type = "text/css";
  195.         style.innerHTML = css;
  196.         document.getElementsByTagName('head')[0].appendChild(style);
  197.     },
  198.     
  199.     cacheContinue: function() {
  200.         var curl = window.location.href;
  201.         var res = selectAllNodes(document, document.body.childNodes[1], ".//a[@href]");
  202.         if (!document.title.match(/^cache/)) {
  203.             for (var x=0; x<res.length; x++) {
  204.                 if (res[x].protocol == 'http:' || res[x].protocol == 'https:') {
  205.                     res[x].href = curl.replace(/cache:.*?\+/,'cache:'+encodeURIComponent(res[x].href)+'+');
  206.                 }
  207.             }
  208.         } else {
  209.             var match = curl.match(/cache:(.*?)\+/);
  210.             if (match) {
  211.                 window.location.href = decodeURIComponent(match[1]);
  212.             }
  213.         }
  214.     },
  215.     
  216.     removeInternalAds: function() {
  217.         var toolbar = document.evaluate("//a[contains(@href,'http://tools.google.com/firefox')]/ancestor::table[@cellpadding='9'][@border='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  218.         if (toolbar) {
  219.             toolbar.parentNode.removeChild(toolbar);
  220.         }
  221.     },
  222.     
  223.     removeSponsoredLinksById: function(ids) {
  224.         for(var i = 0; i < ids.length; i++) {
  225.             var ad = document.getElementById(ids[i]);
  226.             while (ad && ad.parentNode) {
  227.                 ad.parentNode.removeChild(ad);
  228.                 ad = document.getElementById(ids[i]);
  229.             }
  230.         }
  231.     },
  232.     
  233.     removeSponsoredLinksByIdGmail: function(ids) {
  234.         for(var i = 0; i < ids.length; i++) {
  235.             var ad = document.getElementById(ids[i]);
  236.             if (ad && ad.parentNode && (ad.parentNode.className == 'rh' || ad.parentNode.className == 'rhs')) {
  237.                 ad.parentNode.removeChild(ad);
  238.             }
  239.         }
  240.     },
  241.     removeSponsoredLinksGmail: function(ids) {
  242.         this.addGlobalStyle('.slwyWc { display: none !important }');
  243.     },
  244.     
  245.     removeSponsoredLinksFrame: function() {
  246.         this.addGlobalStyle('iframe[name="google_ads_frame"] { display: none !important }');
  247.     },
  248.     
  249.     isRegExp: function(filter) {
  250.         return filter.match(/^\/.+\/[i]?$/);
  251.     },
  252.  
  253.     convertToRegExp: function(pattern) {
  254.         var s = new String(pattern);
  255.         var res = new String("^");
  256.         for (var i = 0 ; i < s.length ; i++) {
  257.             switch(s[i]) {
  258.                 case '*' : 
  259.                     res += ".*";
  260.                     break;
  261.                 case '.' : 
  262.                 case '?' :
  263.                 case '^' : 
  264.                 case '$' : 
  265.                 case '+' :
  266.                 case '{' :
  267.                 case '[' : 
  268.                 case '|' :
  269.                 case '(' : 
  270.                 case ')' :
  271.                 case ']' :
  272.                     res += "\\" + s[i];
  273.                     break;
  274.                 case '\\' :
  275.                     res += "\\\\";
  276.                     break;
  277.                 case ' ' :
  278.                     // Remove spaces from URLs.
  279.                     break;
  280.                 default :
  281.                     res += s[i];
  282.                     break;
  283.             }
  284.         }
  285.         return res + '$';
  286.     },
  287.     
  288.     removeSponsoredLinksRight: function() {
  289.         var ra = document.evaluate("//table[@align='right'][@width='25%'][@border='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  290.         if (ra) {
  291.             ra.parentNode.removeChild(ra);
  292.         } else {
  293.             // update 2008-03-13
  294.             ra = document.evaluate("//table[@align='right'][@width='30%'][@border='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  295.             if (ra) {
  296.                 ra.parentNode.removeChild(ra);
  297.             }
  298.         }
  299.     },
  300.     
  301.     removeSponsoredLinksProducts: function() {
  302.         var res = selectAllNodes(document, document.body, "//table[@width='100%'][@bgcolor='#e5ecf9']");
  303.         for (var x=0; x<res.length; x++) {
  304.             res[x].parentNode.removeChild(res[x]);
  305.         }
  306.         var fr = document.evaluate("//table[@align='right'][@bgcolor='#ffffff'][@border='0'][@cellspacing='0'][@cellpadding='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  307.         if (fr) {
  308.             fr.parentNode.removeChild(fr);
  309.         }
  310.     },
  311.  
  312.     removeSponsoredLinksLocal: function() {
  313.         var s = document.createElement("style");
  314.         s.setAttribute("type","text/css");
  315.          //s.innerHTML=(".ads, #mclip {display: none !important;}");
  316.         //Changed on 16-08-2009
  317.         s.innerHTML=(".ads{display: none !important;}");
  318.         document.body.appendChild(s);
  319.     },
  320.     
  321.     removeSponsoredLinksPrint: function() {
  322.         var ra = document.evaluate("//table[@class='lads']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  323.         if (ra) {
  324.             ra.parentNode.removeChild(ra);
  325.         }
  326.         var ta = document.evaluate("//td[@class='btblinks']/ancestor::table[@style='margin-bottom: 0.8em;']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  327.         if (ta) {
  328.             ta.parentNode.removeChild(ta);
  329.         }    
  330.         var ad = document.getElementById('bottom_ad');
  331.         if (ad) {
  332.             ad.parentNode.removeChild(ad);
  333.         }
  334.     },
  335.     
  336.     removeSponsoredLinksImages: function() {
  337.         var ra = document.evaluate("//table[contains(@style,'255, 249, 221')]/parent::td/parent::tr/parent::tbody/parent::table", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  338.         if (ra) {
  339.             ra.parentNode.removeChild(ra);
  340.         }
  341.     },
  342.     
  343.     removeSearchWiki: function() {
  344.         this.addGlobalStyle('#wml,.w10,.w20,.wcd,.wci,.wce{display:none!important}');
  345.     },
  346.     
  347.     removeSponsoredLinksYouTube: function() {
  348.         this.addGlobalStyle('#search-pva, #leaderboardAd, #ad_creative_1, .ad-div, #watch-channel-brand-div, #chrome-promo {display:none!important}');
  349.  
  350.         /*
  351.         var player = document.getElementById("watch-player-div");
  352.         if (player && document.getElementById("embed_code").value.indexOf("<") != -1){
  353.             var embed_code = document.getElementById("embed_code").value;
  354.             embed_code = embed_code.replace(/height="[0-9]+"/g, 'height="385"');
  355.             embed_code = embed_code.replace(/width="[0-9]+"/g, 'width="640"');
  356.             embed_code = embed_code.replace(/&fs=1/g, '&fs=1&showsearch=0&ap=%2526fmt%3D18');
  357.             player.innerHTML = embed_code;
  358.         }
  359.         */
  360.     },
  361.  
  362.     hideGmailSpam: function(spamname) {
  363.         //if (spamname) {
  364.             //spamname = spamname.replace(/^\s*|\s*$/g,"");
  365.             //this.addGlobalStyle('#ds_spam b {visibility: hidden;}');
  366.             //this.addGlobalStyle('#ds_spam b::before {content: "'+spamname+'"; visibility: visible; font-weight: normal;}');
  367.             //this.addGlobalStyle("span#ds_spam b,.ACpQre a[href$='#spam']{visibility:hidden;}span#ds_spam b::before,.ACpQre a[href$='#spam']::before{content:'"+spamname+"';visibility:visible;font-weight:400;text-decoration:none;}");
  368.             //this.addGlobalStyle("span#ds_spam b,.ACpQre a[href$='#spam']{visibility:hidden;}span#ds_spam b::before,.ACpQre a[href$='#spam']::before{content:'"+spamname+"';visibility:visible;font-weight:400;}");
  369.  
  370.             var canvas = document.getElementById("canvas_frame");
  371.             if (!canvas) {
  372.                 canvas = document;
  373.             } else {
  374.                 canvas = canvas.contentDocument;
  375.             }
  376.             var spam = canvas.evaluate("//a[contains(@href,'#spam')]", canvas, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
  377.                     || canvas.evaluate("//a[contains(@href,'?s=m')]", canvas, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  378.             if (spam) {
  379.                 spam.innerHTML = spam.innerHTML.replace(/( |[\s]*)\(\d+\)/, "");
  380.                 spam.style.fontWeight = "normal";
  381.             } else {
  382.                 window.setTimeout(OptimizeGoogle.hideGmailSpam, 500);
  383.             }
  384.             
  385.             
  386.  
  387.         //}
  388.     },
  389.     
  390.     hideID: function(id) {
  391.         var s = document.createElement("style");
  392.         s.setAttribute("type","text/css");
  393.          s.innerHTML=("#" + id + "{display: none !important;}");
  394.         document.body.appendChild(s);
  395.     },
  396.     hideClass: function(id) {
  397.         this.addGlobalStyle("." + id + "{display: none !important;}");
  398.     },
  399.     
  400.     useMonoSpaceFont: function() {
  401.          this.addGlobalStyle(".mb, .tb, .compose .mi, div.msg, .ArwC7c, .iE5Yyc {font-family: MonoSpace !important; font-size: 90% !important; }");
  402.     },
  403.     
  404.     addOtherWebSearches: function(urls) {
  405.         var header = document.evaluate("//div[@id='ssb']",                                                        document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
  406.             || document.evaluate("//div[@class='bb bt t']",                                                        document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
  407.             || document.evaluate("//table[@class='t bt'][@width='100%'][@cellspacing='0'][@cellpadding='0']",    document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  408.         if (!header) return;
  409.         if (!document.gs || !document.gs.q) return;
  410.         var q = encodeURIComponent(document.gs.q.value);
  411.         var q2 = escape(document.gs.q.value);
  412.         if (!q) return;
  413.         var other = document.createElement('div');
  414.         other.setAttribute("style", "font-size:small;padding:8px 0 0 0;");
  415.         if (document.cookie && document.cookie.match(/:NW=1:/)) {
  416.             urls = urls.replace(/a href/ig, "a target=nw href");
  417.         }
  418.         other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
  419.         header.parentNode.insertBefore(other, header.nextSibling);
  420.     },
  421.     
  422.     addOtherImageSearches: function(urls) {
  423.         var table = document.evaluate("//table[@class='t bt'][@width='100%'][@cellspacing='0'][@cellpadding='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  424.         if (!table) return;
  425.         if (!document.gs || !document.gs.q) return;
  426.         var q = encodeURIComponent(document.gs.q.value);
  427.         var q2 = escape(document.gs.q.value);
  428.         
  429.         if (document.cookie.match(/:NW=1:/)) {
  430.             urls = urls.replace(/a href/ig, "a target=nw href");
  431.         }
  432.         
  433.         var other = document.createElement('div');
  434.         other.setAttribute("style", "font-size:small;padding:4px 0 0 0;");
  435.         other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
  436.         
  437.         table.parentNode.insertBefore(other, table.nextSibling);
  438.     },
  439.     
  440.     addOtherBlogSearches: function(urls) {
  441.         var table = document.evaluate("//table[@class='ttt'][@width='100%'][@cellspacing='0'][@cellpadding='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  442.         if (!table) return;
  443.         if (!document.gs || !document.gs.q) return;
  444.         var q = encodeURIComponent(document.gs.q.value);
  445.         var q2 = escape(document.gs.q.value);
  446.         
  447.         if (document.cookie.match(/:NW=1:/)) {
  448.             urls = urls.replace(/a href/ig, "a target=nw href");
  449.         }
  450.         
  451.         var other = document.createElement('div');
  452.         other.setAttribute("style", "font-size:small;padding:4px 0 0 0;");
  453.         other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
  454.         
  455.         table.parentNode.insertBefore(other, table.nextSibling);
  456.     },
  457.  
  458.     addOtherVideoSearches: function(urls) {
  459.         var table = document.evaluate("//table[@id='resultsheadertable']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  460.         if (!table) return;
  461.         if (!document.f || !document.f.q) return;
  462.         var q = encodeURIComponent(document.f.q.value);
  463.         var q2 = escape(document.f.q.value);
  464.         if (document.cookie.match(/:NW=1:/)) {
  465.             urls = urls.replace(/a href/ig, "a target=nw href");
  466.         }
  467.         
  468.         var other = document.createElement('div');
  469.         other.setAttribute("style", "font-size:small;padding:4px 0 4px 5px;");
  470.         other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
  471.         
  472.         table.parentNode.insertBefore(other, table.nextSibling);
  473.     },
  474.     
  475.     addOtherNewsSearches: function(urls) {
  476.         //Alternative from 0.76.2 Doesn't seem to work any better.
  477.         //var table = document.evaluate("//font[@class='ks']/ancestor::table[@cellspacing='0'][@cellpadding='0'][@border='0'][@width='100%']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  478.         var table = document.evaluate("//font[@class='ks']/parent::td/parent::tr/parent::tbody/parent::table", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  479.         if (!table) return;
  480.         if (!document.gs || !document.gs.q) return;
  481.         var q = encodeURIComponent(document.gs.q.value);
  482.         var q2 = escape(document.gs.q.value);
  483.         
  484.         if (document.cookie.match(/:NW=1:/)) {
  485.             urls = urls.replace(/a href/ig, "a target=nw href");
  486.         }
  487.  
  488.         var other = document.createElement('div');
  489.         other.setAttribute("style", "font-size:small;padding:4px 0 4px 5px;");
  490.         other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
  491.  
  492.         table.parentNode.insertBefore(other, table.nextSibling);
  493.     },
  494.     
  495.     addOtherProductSearches: function(urls) {
  496.         var table = document.evaluate("//table[@id='ps-titlebar'][@cellspacing='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  497.         if (!table) return;
  498.         var frm = document.gs || document.f;
  499.         if (!frm || !frm.q) return;
  500.         
  501.         var q = encodeURIComponent(frm.q.value);
  502.         var q2 = escape(frm.q.value);
  503.         
  504.         if (document.cookie.match(/:NW=1:/)) {
  505.             urls = urls.replace(/a href/ig, "a target=nw href");
  506.         }
  507.         
  508.         var other = document.createElement('div');
  509.         other.setAttribute("style", "font-size:small;padding:4px 0 4px 5px;");
  510.         other.innerHTML = this.t("try_search") + ' ' + urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
  511.  
  512.         table.parentNode.insertBefore(other, table.nextSibling);
  513.     },
  514.     
  515.     addFavicons: function() {
  516.         //Changed 16-08-2009
  517.         var list = document.evaluate("//li[@class='g' or @class='g w0']/descendant::h3/a", document, null, 6, null);
  518.         for (var i=0; i < list.snapshotLength; ++i) {
  519.             var a = list.snapshotItem(i);
  520.  
  521.             var url = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%06%00%00%00%1F%F3%FFa%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%00%EDIDATx%DA%A4%93K%0A%830%10%86'%A1%1B%1F%E0%CA%13%E8%D6%95'%D1%A5%97%F4%1C%0A%5Dy%02%2F%E0%0B%1F%08%82%25%A1%13%F2%B2%B5t%60H%C8%FC%FF7%1A%1Dr%9E'%FC%13%0F%DC%94e%99%EA%C5y%9E%C1%F7%7D%BE%CF%B2%EC%F9%11%F0%16)%C5m%DB%C0q%1CX%D7%15%9A%A6I%93%241%20T%3F%60b%CCeY%F8%99%EB%BA%10E%11%B4m%9B~%05%5C%05%83%84ah%BC%AA%00%DC%B9L%06%D1u%E2%0E%A6i%B2%9A%AA%AA%E2%2B!%04(%A5P%D75%E4yn%02%C6q%B4%02%E28%E6f%CC%20%08%ECO%D0%F7%BDa%F6%3C%8Fw%C5%EE%2C%F6%7D%B7%03%BA%AES%0AhB%00%A6%AE%13%80a%18%D4%CF%23%99q%B5%E9%04%E08%0E%C5%2Cw%C5%D4u%97%FF%81l%92%BB%DB%82%DA%CC%F2z%7B%98X%14E%F1%F34%92%7F%C7%F9%25%C0%00%F6%19T%09%A3%B3%D1%A8%00%00%00%00IEND%AEB%60%82";
  522.             if (a.href.match(/\/interstitial\?url=/)) {
  523.                 url = "data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%06%00%00%00%1F%F3%FFa%00%00%00%04gAMA%00%00%AF%C87%05%8A%E9%00%00%00%19tEXtSoftware%00Adobe%20ImageReadyq%C9e%3C%00%00%02OIDAT8%CB%A5%93%CBK%94a%14%C6%1F%BF%D4%09%95%E9SA%9C%11oc%8A%94%AB%886%E1%C6.PD%04C%8B%C4%0B%B8%EA%82%F4%17D%10%15%D5%A2%CD%40%ABZx%C1h1%E0N%10%8C%A2%22%A4%85C%8DN%A9%A3%98%3Av%19%9D%14%9Df%E6%7D%CF%F3%B6%B0%BE%19%B36uv%EF%E1%9C%DFy%0E%EFy%F2%8C1%F8%9F%C8%FF%3D!%B7%AF4%D0%98vCv%91%AC%24%09%92%9FH%F6S8d%DF%E9%8F%E6%D6%E7%E5*P%B7.%FB%0DM%60%2B%AF%D0S%D8%B0%1F%F9n%F7v~c%1D%C9H%04Vr%7D%85%94%DE%8A%FBO%82%BB%00%99%9B%97%FC%86%ECKW%D4%14%1755Bb%0B%60l%01%00%60yj%60yk%B11%15Aj%FA%DD%16E%BA%AB%1F%0C%07%1D%40%FA%C6E%1F%C9%17%99%CA%1AoqS%132%AFF%01%00E%D7%1E%02%006%AF%F7%004(l%3D%89%F5%F0%246%23%131!%5B%F7%3F%1A%99%B3%00%40Dw%24-W%B6%D9%18%18fW%A3%26D%1B%24%C7F%E0n%3E%00SR%EE%D5Ju%00%80%05%00Z%EBNWc%23di%1E%86%06%14%03%A3%B9%03%40%25%90%0C%91%9E%8Bb_s%0B%94R%9D%B9%80%AA%02%DB%86%5E%9C%87%D1t%26%3A%3F%93!Dm%E7S%B3Q%14%D8e%D0JWe%01J%C3%88q%1A%7FMT%D3%E1%EC%0A%EA'D%08%08%A1%B5B%8E%02%B5%9C%8E%AF%C1%F2%D4%3ARE%11%DF_%8Eas%F8%B13%9D%8A%C8%AF%AEC2%1E%87Vz9W%C1%C0%B7%F0%5B%EC%F1%D69%C5%A2%08w%CFU%94%9C%BB%00*B4!B%B8%EA%7C%F8%12z%03%AD%F5%80%03PJ%0DfVc%B1%C4d%18Em%A7%1C%C8Z%E0%1EV%03w!%B2%FD%B6O%9F%C1%D7p%08%89%C5%99%98%D6zp%C7!Mu%1E%F3S%A4%CF%3Ex%A4%B8%B4%B9%05%A9%F99%A4f%A30%C6%C0U%EF%83%AB%DE%87x8%84%8F%AFG%B7Hv%B7%3D%7D%1F%DCu%CA%A1%F3G%FDB%06%F6%96y%3D%E5-%87%E0%B2Ka%0C%90J%AC%E1%F3%C48%12K%B3%2B%24%7B%8F%3F%FB%10%FC%A3%17%00%60%FC%EC%E1%06%92%ED%14v%91%B2%D3L%E4%D0%89%E73%7F7%D3%BF%C4%0F%95%D1%AFLj%05%EB%FF%00%00%00%00IEND%AEB%60%82";
  524.             }
  525.             
  526.             var img = new Image();
  527.             img.src = url;
  528.             img.setAttribute("style","height:16px;width:16px;border:0;padding-top:2px;padding-right:4px;display:block;float:left;");
  529.             a.parentNode.parentNode.insertBefore(img, a.parentNode.nextSibling);
  530.             (function(a,img){
  531.             if (!a.href.match(/^https/) && !a.href.match(/\/interstitial\?url=/)) {
  532.                 var url = "http://"+a.href.split('/')[2]+"/favicon.ico";
  533.                 var tmpimg = new Image();
  534.                 tmpimg.src = url;
  535.                 tmpimg.addEventListener("load",function() { img.src = url; },false);
  536.             }
  537.             })(a,img);
  538.         }
  539.     },
  540.     
  541.     removeUrlClickTrack: function() {
  542.         var match = null;
  543.         var a = selectAllNodes(document,document.body,"//a[@href]");
  544.         for (var y=0; y<a.length; y++) {
  545.             // if internal
  546.             match = a[y].href.match(/^http:\/\/[^\/]*google\.[a-z\.]+\/(aclk|pagead|url).+?(url|q|adurl)=(http[s]?:[^&]+)/i);
  547.             if (match) {
  548.                 a[y].href = unescape(match[3]);
  549.             }
  550.             // if external
  551.             if (a[y].href.match(/^(http|https|ftp):\/\//) && !a[y].href.match(/google\.[a-z\.]+\//)) {
  552.                 a[y].onmousedown = function() { return true; }
  553.             }
  554.         }
  555.         // sneaky google sometimes bypass the above, this will fix it
  556.         window.clk = function() { };
  557.     },
  558.     
  559.     showAdPreviews: function() {
  560.         var match = null;
  561.         var a = selectAllNodes(document, document.body, "//a");
  562.         for (var y=0; y<a.length; y++) {
  563.             match = a[y].href.match(/^http:\/\/[^\/]*google\.[a-z\.]+\/(pagead|url).+?(q|adurl)=(http[s]?:[^&]+)/i);
  564.             if (match) {
  565.                 a[y].onmouseover = function() { };
  566.             }
  567.             
  568.         }
  569.         var td = selectAllNodes(document, document.body, "//td[@onmouseover='return ss()']");
  570.         for (var y=0; y<td.length; y++) {
  571.             td[y].onmouseover = function() { };
  572.         }
  573.         td = selectAllNodes(document, document.body, "//td[@onmouseover='return true']");
  574.         for (var y=0; y<td.length; y++) {
  575.             td[y].onmouseover = function() { };
  576.         }
  577.     },
  578.  
  579.     filterWebsitesFromSearch: function(preflist,color) {
  580.     
  581.         var prefarr = preflist.split(/\s+/);
  582.         var l = new Array();
  583.         for (var i=0;i< prefarr.length;i++) {
  584.             var cg_regexp = null;
  585.             if (!this.isRegExp(prefarr[i])) {
  586.                 cg_regexp = new RegExp(this.convertToRegExp(prefarr[i]), "i");
  587.             } else {
  588.                 cg_regexp = new RegExp(prefarr[i].replace(/^\/(.+)\/[i]?$/, "($1)"), "i");
  589.             }
  590.             l[l.length] = cg_regexp;
  591.         }
  592.     
  593.         var re = null;
  594.         var match = null;
  595.         //var res = selectAllNodes(document, document.body, "//li[contains(@class,'g')]");
  596.         //Changed 16-08-2009
  597.         var res = selectAllNodes(document, document.body, "//li[@class='g' or @class='g w0']");
  598.         for (var x=0; x<res.length; x++) {
  599.             var a = document.evaluate(".//a", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  600.             if (!a) continue;
  601.             var lnk = a.href;
  602.             
  603.             match = lnk.match(/^(http:\/\/www\.google|\/url).+?q=(.+)(&|&)e=/i);
  604.             if (match) {
  605.                 lnk = unescape(match[2]);
  606.             }
  607.             
  608.             var nobr = document.evaluate(".//span[@class='gl']", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr/font", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  609.             if (nobr) {
  610.                 nobr.innerHTML = nobr.innerHTML + ' - ';
  611.  
  612.                 var newa = document.createElement('a');
  613.                 newa.setAttribute("href", "javascript:void(0);");
  614.                 newa.setAttribute("cg_filter", lnk);
  615.                 newa.setAttribute("class", "fl");
  616.                 if (document.cookie.match(/:NW=1:/)) {
  617.                     newa.setAttribute("target", "nw");
  618.                 }
  619.                 newa.innerHTML = this.t("filter");
  620.                 nobr.appendChild(newa);
  621.             }
  622.             
  623.             if (l && l.length > 0) {  
  624.                 for (var i=0;i< l.length;i++) {
  625.                     if (lnk.match(l[i])) {
  626.                         var np = document.createElement('li');
  627.                         var npa = document.createElement('a');
  628.                         npa.setAttribute("href", lnk);
  629.                         npa.setAttribute("style", "color:"+color+";text-decoration:none;");
  630.                         npa.setAttribute("title", this.t("filter_match"));
  631.                         npa.setAttribute("class", "l");
  632.                         npa.innerHTML = lnk;
  633.                         np.appendChild(npa);
  634.                         
  635.                         if (document.cookie.match(/:NW=1:/)) {
  636.                             np.setAttribute("target", "nw");
  637.                         }
  638.                         //np.setAttribute("class", "g w0");
  639.                         //Changed 16-08-2009
  640.                         np.setAttribute("class", "g");
  641.                         np.setAttribute("style", "font-size:small;");
  642.                         res[x].parentNode.replaceChild(np, res[x]);
  643.                         break;
  644.                     }
  645.                 }
  646.             }
  647.         }
  648.     },
  649.     
  650.     filterWebsitesFromNews: function(preflist, color) {
  651.         var prefarr = preflist.split(/\s+/);
  652.         var l = new Array();
  653.         for (var i=0;i< prefarr.length;i++) {
  654.             var cg_regexp = null;
  655.             if (!this.isRegExp(prefarr[i])) {
  656.                 cg_regexp = new RegExp(this.convertToRegExp(prefarr[i]), "i");
  657.             } else {
  658.                 cg_regexp = new RegExp(prefarr[i].replace(/^\/(.+)\/[i]?$/, "($1)"), "i");
  659.             }
  660.             l[l.length] = cg_regexp;
  661.         }
  662.     
  663.         var re = null;
  664.         var match = null;
  665.         var res = selectAllNodes(document, document.body, "//table[@cellspacing='7'][@cellpadding='2'][@border='0'][@valign='top']");
  666.         for (var x=0; x<res.length; x++) {
  667.             var counter = selectAllNodes(document, res[x], ".//a");
  668.             if (!counter || counter.length > 2) continue;
  669.             
  670.             var a = document.evaluate(".//a", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  671.             if (!a) continue;
  672.             var lnk = a.href;
  673.             
  674.             match = lnk.match(/^(http:\/\/www\.google|\/url).+?q=(.+)(&|&)e=/i);
  675.             if (match) {
  676.                 lnk = unescape(match[2]);
  677.             }
  678.             
  679.             var nobr = document.evaluate(".//nobr/font", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  680.             if (nobr) {
  681.                 var span = document.createElement('span');
  682.                 span.innerHTML = ' - ';
  683.                 nobr.appendChild(span);
  684.                 var newa = document.createElement('a');
  685.                 newa.setAttribute("href", "javascript:void(0);");
  686.                 newa.setAttribute("cg_filter", lnk);
  687.                 newa.setAttribute("class", "fl");
  688.                 newa.innerHTML = this.t("filter");
  689.                 nobr.appendChild(newa);
  690.             }
  691.             
  692.             if (l && l.length > 0) {
  693.                 for (var i=0;i< l.length;i++) {
  694.                     if (lnk.match(l[i])) {
  695.                         var np = document.createElement('div');
  696.                         var npa = document.createElement('a');
  697.                         npa.setAttribute("href", lnk);
  698.                         npa.setAttribute("style", "color:"+color+";text-decoration:none;");
  699.                         npa.setAttribute("title", this.t("filter_match"));
  700.                         npa.innerHTML = lnk;
  701.                         np.appendChild(npa);
  702.                         np.setAttribute("style", "font-size:small;margin-left:5px;");
  703.                         res[x].parentNode.replaceChild(np, res[x]);
  704.                         break;
  705.                     }
  706.                 }
  707.             }
  708.         }
  709.     },
  710.     
  711.     addWayBackMachine: function() {
  712.         var match = null;
  713.         //var res = selectAllNodes(document, document.body, "//li[contains(@class,'g')]");
  714.         //Changed 16-08-2009
  715.         var res = selectAllNodes(document, document.body, "//li[@class='g' or @class='g w0']");
  716.         for (var x=0; x<res.length; x++) {
  717.             var a = document.evaluate(".//a", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  718.             if (!a) continue;
  719.             
  720.             var lnk = a.href;
  721.             match = lnk.match(/^(http:\/\/www\.google|\/url).+?q=(.+)(&|&)e=/i);
  722.             if (match) {
  723.                 lnk = unescape(match[2]);
  724.             }
  725.             
  726.             var nobr = document.evaluate(".//span[@class='gl']", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr/font", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  727.             if (nobr) {
  728.                 nobr.innerHTML = nobr.innerHTML + ' - ';
  729.                 
  730.                 var newa = document.createElement('a');
  731.                 newa.setAttribute("href", "http://web.archive.org/web/*/" + lnk);
  732.                 newa.setAttribute("class", "fl");
  733.                 
  734.                 if (document.cookie.match(/:NW=1:/)) {
  735.                     newa.setAttribute("target", "nw");
  736.                 }
  737.                 
  738.                 newa.innerHTML = this.t("history");
  739.                 nobr.appendChild(newa);
  740.             }
  741.         }
  742.     },
  743.     
  744.     addBookmarks: function(handler) {
  745.         
  746.         if (!document.gs || !document.gs.q) return;
  747.         var q = encodeURIComponent(document.gs.q.value);
  748.         if (!q) return;
  749.         
  750.         var match = null;
  751.         //var res = selectAllNodes(document, document.body, "//li[contains(@class,'g')]");
  752.         //Changed 16-08-2009
  753.         var res = selectAllNodes(document, document.body, "//li[@class='g' or @class='g w0']");
  754.         for (var x=0; x<res.length; x++) {
  755.             var a = document.evaluate(".//a", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  756.             if (!a) continue;
  757.             
  758.             var lnk = a.href;
  759.             var title = a.innerHTML.replace(/<[^>]+>/g,"");
  760.             
  761.             match = lnk.match(/^(http:\/\/www\.google|\/url).+?q=(.+)(&|&)e=/i);
  762.             if (match) {
  763.                 lnk = unescape(match[2]);
  764.             }
  765.             
  766.             var nobr = document.evaluate(".//span[@class='gl']", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr/font", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue || document.evaluate(".//nobr", res[x], null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  767.             if (nobr) {
  768.                 nobr.innerHTML = nobr.innerHTML + ' - ';
  769.                 var newa = document.createElement('a');
  770.                 newa.setAttribute("class", "fl");
  771.                 
  772.                 switch (handler){
  773.                     case "del.icio.us":
  774.                         newa.setAttribute("href", "http://del.icio.us/post?title=" + encodeURIComponent(title) + "&url=" + encodeURIComponent(lnk) + "&encoding=UTF-8&tags=" + q);
  775.                         break;
  776.                     case "furl":
  777.                         newa.setAttribute("href", "http://www.furl.net/storeIt.jsp?t=" + encodeURIComponent(title) + "&u=" + encodeURIComponent(lnk) + "&encoding=UTF-8&tags=" + q);
  778.                         break;
  779.                     case "digg":
  780.                         newa.setAttribute("href", "http://digg.com/submit?phase=2&url=" + encodeURIComponent(lnk) + "&encoding=UTF-8&tags=" + q);
  781.                         break;
  782.                     case "spurl":
  783.                         newa.setAttribute("href", "http://www.spurl.net/spurl.php?v=3&title=" + encodeURIComponent(title) + "&url=" + encodeURIComponent(lnk) + "&encoding=UTF-8&tags=" + q);
  784.                         break;
  785.                     case "simpy":
  786.                         newa.setAttribute("href", "http://simpy.com/simpy/LinkAdd.do?title=" + encodeURIComponent(title) + "&href=" + encodeURIComponent(lnk) + "&encoding=UTF-8&v=6&tags=" + q);
  787.                         break;
  788.                     case "blinklist":
  789.                         newa.setAttribute("href", "http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=" + encodeURIComponent(lnk) + "&Title=" + encodeURIComponent(title) + "&encoding=UTF-8&Tag=" + q);
  790.                         break;
  791.                     case "yahoo-myweb":
  792.                         newa.setAttribute("href", "http://synergy2.search.yahoo.com/myresults/bookmarklet?u=" + encodeURIComponent(lnk) + "&t=" + encodeURIComponent(title) + "&encoding=UTF-8&Tag=" + q);
  793.                         break;
  794.                     case "google":
  795.                         newa.setAttribute("href", "http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" + encodeURIComponent(lnk) + "&title=" + encodeURIComponent(title));
  796.                         break;
  797.                     case "ma.gnolia":
  798.                         newa.setAttribute("href", "http://ma.gnolia.com/bookmarklet/popup/add?url=" + encodeURIComponent(lnk) + "&title=" + encodeURIComponent(title) + "&description=");
  799.                         break;
  800.                     case "reddit":
  801.                         newa.setAttribute("href", "http://reddit.com/submit?url=" + encodeURIComponent(lnk));
  802.                         break;
  803.                     default:
  804.                         newa.setAttribute("href", "javascript:void(0);");
  805.                         newa.setAttribute("cg_url", lnk);
  806.                         newa.setAttribute("cg_title", title);
  807.                 }
  808.                 
  809.                 if (document.cookie.match(/:NW=1:/)) {
  810.                     newa.setAttribute("target", "nw");
  811.                 }
  812.                 
  813.                 newa.innerHTML = this.t("save");
  814.                 nobr.appendChild(newa);
  815.             }
  816.         }
  817.     },
  818.  
  819.     restoreGooglePrint: function() {
  820.         var cleardots = document.evaluate("//img[@src='/images/cleardot.gif']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  821.         var cleardot, i, div, theimg;
  822.         for(cleardot = null, i = 0; (cleardot = cleardots.snapshotItem(i)); i++) {
  823.             div = cleardot.parentNode;
  824.             if (div.nodeName != "DIV") {
  825.                 div = div.parentNode;
  826.             }
  827.             theimg = getComputedStyle(div, '').backgroundImage;
  828.             theimg = theimg.replace(/url\((.*?)\)/g, "$1");
  829.             cleardot.style.border = "none";
  830.             cleardot.src = theimg;
  831.         }
  832.         
  833.         document.oncontextmenu = null;
  834.     },
  835.     
  836.     addOtherBookReviews: function(urls) {
  837.         var table = document.evaluate("//table[@bgcolor='#e5ecf9'][@width='100%'][@border='0'][@cellpadding='1'][@cellspacing='0']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  838.         if (!table) return;
  839.         if (!document.gs || !document.gs.q) return;
  840.         var q = encodeURIComponent(document.gs.q.value);
  841.         var q2 = escape(document.gs.q.value);
  842.         if (!q) return;
  843.         
  844.         if (document.cookie.match(/:NW=1:/)) {
  845.             urls = urls.replace(/a href/ig, "a target=nw href");
  846.         }
  847.  
  848.         var other = document.createElement('div');
  849.         var s = '<span style="font-size:small;padding:4px 0 4px 5px;">' + this.t("try_search") + ' ';
  850.         s += urls.replace(/\[QUERY\]/g, q).replace(/\[QUERYISO88591\]/g, q2);
  851.         s += '</span>';
  852.         other.innerHTML = s;
  853.         table.parentNode.insertBefore(other, table.nextSibling);
  854.     },
  855.     
  856.     addGoogleSuggest: function() {
  857.             
  858.         // only add suggest if it is not there already
  859.         if (!document.body.innerHTML.match(/google\.ac\.i\(document/)) {
  860.             var f = get_search_form();
  861.             if (!f || !f.q) return;
  862.             if (!window.google)    window.google={};
  863.             if (!window.google.y || !window.google.y.first) window.google.y={first:[]};
  864.             window.setTimeout(function(){var xjs=document.createElement('script');
  865.             xjs.src='/extern_js/f/CgJlbiswCjgNLCswDjgELCswGDgDLA/F21IcsWnMZA.js';
  866.             document.getElementsByTagName('head')[0].appendChild(xjs)},0);
  867.             window.google.y.first.push(function(){window.google.ac.i(f,f.q,'','')})
  868.             f.q.setAttribute("autocomplete", "off");
  869.         }
  870.     },
  871.     
  872.     pointLinksToImages: function() {
  873.         createLinks();
  874.         window.addEventListener("resize", createLinks, true);
  875.     },
  876.     
  877.     secureGoogle: function() {
  878.         if (window.location.href.match(/^http:/)) {
  879.             window.location.href = window.location.href.replace(/^http:/, 'https:');
  880.         }
  881.      },
  882.     anonymizeGoogleUID: function() {
  883.         if (location.host.match(/google\..+$/)) {
  884.             var domain = location.host.match(/google\..+$/)[0];
  885.             var parts  = document.cookie.split('; ');
  886.             var c = null;
  887.             for(var i=0; c=parts[i]; ++i) {
  888.                 if(c.match(/^PREF=/)) {
  889.                     document.cookie = c.replace(/ID=\w+:/,'ID='+get_random_id(16)+':') + '; domain=.' + domain + '; path=/; expires=Mon, 01 Jan 2038 00:00:00 GMT';
  890.                 }
  891.             }
  892.         }
  893.      },
  894.  
  895.     defaultPreferences: function(FF,LR,LD,NR,NW,SG) {
  896.         var domain = location.host.match(/google\..+$/)[0];
  897.         var parts  = document.cookie.split('; ');
  898.         var c = null;
  899.             
  900.         for(var i=0; c=parts[i]; ++i) {
  901.             // if pref cookie
  902.             if (c.match(/^PREF=/)) {
  903.                 // parse cookie
  904.                 var namevalues = c.match(/^PREF=(.*)/)[1].split(':');
  905.                 var hash   = new Object();
  906.                 for(var j=0; j < namevalues.length; j++) {
  907.                     var pair = namevalues[j].split('=');
  908.                     hash[pair[0]] = pair[1];
  909.                 }
  910.                 
  911.                 // if valid cookie
  912.                 if (hash['ID'] && hash['TM'] && hash['LM'] && hash['S']) {
  913.                 
  914.                     var modified = false;
  915.                     
  916.                     // SafeSearch: 4 = Off, 1 = Strict, empty = Moderate
  917.                     // if set but should be empty
  918.                     if (FF && hash['FF'] && FF == 'empty') {
  919.                         hash['FF'] = '';
  920.                         modified = true;
  921.                     // if set but not should be empty
  922.                     }  else if (FF && hash['FF'] && FF != hash['FF'] && FF != 'empty') {
  923.                         hash['FF'] = FF;
  924.                         modified = true;
  925.                     // if not set and should not be empty
  926.                     } else if (FF && !hash['FF'] && FF != 'empty') {
  927.                         hash['FF'] = FF;
  928.                         modified = true;
  929.                     }
  930.                     
  931.                     // Search only for pages written in these language(s)
  932.                     // if set but should be empty
  933.                     if (LR && hash['LR'] && LR == 'empty') {
  934.                         hash['LR'] = '';
  935.                         modified = true;
  936.                     // if set but not should be empty
  937.                     }  else if (LR && hash['LR'] && LR != hash['LR'] && LR != 'empty') {
  938.                         hash['LR'] = LR;
  939.                         modified = true;
  940.                     // if not set and should not be empty
  941.                     } else if (LR && !hash['LR'] && LR != 'empty') {
  942.                         hash['LR'] = LR;
  943.                         modified = true;
  944.                     }
  945.  
  946.                     // Display Google tips and messages in this language
  947.                     if (LD && (!hash['LD'] || LD != hash['LD'])) {
  948.                         hash['LD'] = LD;
  949.                         modified = true;
  950.                     }
  951.                     
  952.                     // Display X results per page
  953.                     if (NR && (!hash['NR'] || NR != hash['NR'])) {
  954.                         hash['NR'] = NR;
  955.                         modified = true;
  956.                     }
  957.  
  958.                     // Open search results in a new browser window.
  959.                     // if set but should be empty
  960.                     if (NW && hash['NW'] && NW == 'empty') {
  961.                         hash['NW'] = '';
  962.                         modified = true;
  963.                     // if set but not should be empty
  964.                     }  else if (NW && hash['NW'] && NW != hash['NW'] && NW != 'empty') {
  965.                         hash['NW'] = NW;
  966.                         modified = true;
  967.                     // if not set and should not be empty
  968.                     } else if (NW && !hash['NW'] && NW != 'empty') {
  969.                         hash['NW'] = NW;
  970.                         modified = true;
  971.                     }
  972.                     
  973.                     // Use Google Suggest
  974.                     // if set but should be empty
  975.                     if (SG && SG == 'empty' && (!hash['SG'] || hash['SG'] != '0')) {
  976.                         hash['SG'] = '0';
  977.                         modified = true;
  978.                     // if set but not should be empty
  979.                     }  else if (SG && SG == '1' && (hash['SG'])) {
  980.                         hash['SG'] = '';
  981.                         modified = true;
  982.                     }
  983.                     
  984.                     // if any changes
  985.                     if (modified) {
  986.                         var newpref = "PREF=";
  987.                         // keep order
  988.                         newpref += 'ID' + '=' + hash['ID'] + ':';
  989.                         // prefs
  990.                         for (key in hash) {
  991.                             if (key != 'ID' && key != 'S' && hash[key]) {
  992.                                 newpref += key + '=' + hash[key] + ':';
  993.                             }
  994.                         };
  995.                         // keep order
  996.                         newpref += 'S'  + '=' + hash['S'];
  997.                         document.cookie = newpref + '; domain=.' + domain + '; path=/; expires=Mon, 01 Jan 2038 00:00:00 GMT';
  998.                         window.location.href = window.location.href;
  999.                     }
  1000.                 }
  1001.                 // else invalid cookie
  1002.                 return;
  1003.             }
  1004.         }
  1005.     },
  1006.     
  1007.     addCountSearchResults: function() {
  1008.         var x, i, p, s=0, n=0, R=/start=([^&]*)/;
  1009.         if ((x=R.exec(document.location.search)) && x[1]) s = n = parseInt(unescape(x[1]),10);
  1010.         //var res = selectAllNodes(document, document.body, "//li[contains(@class,'g')]/descendant::h3/a");
  1011.         //Changed 16-08-2009
  1012.         var res = selectAllNodes(document, document.body, "//li[@class='g' or @class='g w0']/descendant::a[@class='l']");
  1013.         for (i=0;i<res.length;++i) {
  1014.             if (!res[i].getAttribute("href").match(/google\.[a-z\.]+\/(videosearch|products)\?/)) {
  1015.                 var tn  = document.createElement("span");
  1016.                 tn.innerHTML = ++n + ". ";
  1017.                 //var tn = document.createTextNode(++n + ". ");
  1018.                 tn.setAttribute("style", res[i].getAttribute("style"));
  1019.                 res[i].parentNode.insertBefore(tn, res[i]);
  1020.             }
  1021.         };
  1022.     },
  1023.     
  1024.     anonymizeGoogleAnalytics: function() {
  1025.         var parts  = document.cookie.split('; ');
  1026.         var c = null;
  1027.         for(var i=0; c=parts[i]; ++i) {
  1028.             var match = c.match(/^(__utm[a-z])=/);
  1029.             if (match) {
  1030.                 var d = document.domain;
  1031.                 if (d.substring(0,4)=="www.") {
  1032.                     d=d.substring(4,d.length);
  1033.                 }
  1034.                 document.cookie = match[1] + '=; domain=' + d + '; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT';
  1035.             }
  1036.         }
  1037.      },
  1038.     
  1039.     bypassChineseFirewall: function() {
  1040.         // The Chinese Firewall filters infomation on the internet
  1041.         // Google cache is disabled by the supervisor
  1042.         // This method bypass the firewall by rewriting the links
  1043.         var match = null;
  1044.         var a = selectAllNodes(document, document.body, "//a[contains(@href, 'search?q=cache')]");
  1045.         for (var y=0; y<a.length; y++) {
  1046.             a[y].href = a[y].href.replace(/q=cache/, "&q=cache");
  1047.         }
  1048.     },
  1049.     
  1050.     addSearchFieldFocus: function() {
  1051.         var f = get_search_form();
  1052.         if (!f || !f.q) return;
  1053.         window.addEventListener("load", function() {f.q.focus();}, false);
  1054.     }
  1055. };
  1056.